<template>
	<view class="infoBox ">
		<view class="infoTitle" v-if="loading">
			<view style="height: 30rpx;width: 80%;" class="Skeleton" />
		</view>
		<view class="infoTitle" v-else>
			<u-icon name='clock' size='28rpx' />
			<view class="title">
				全部动态
			</view>
			<u-icon name='arrow-down-fill' size='28rpx' :label='processesTitle' labelPos='left' @click='show=true' />
		</view>
		<view class="infoContent">
			<template v-if="loading">
				<view class="userBox">
					<view class="Skeleton" style="height: 80rpx;width: 80rpx;" />
					<view class="userInfo">
						<view class="Skeleton" style="height: 30rpx;" v-for="item in 2" :key="item" />
					</view>
				</view>
				<view v-for="(item,index) in 5" :key="index">
					<view class="Skeleton" style="height: 30rpx;margin-bottom: 20rpx;" v-for="item in 4" :key="item" />
					<view>
						<album :loading='loading' />
					</view>
				</view>
			</template>
			<template v-else>
				<view v-for="(item,index) in active" :key="index" class="mb20 activeBox">
					<view v-if="item.status!=-1" style="margin-bottom: 10rpx;">
						<u-notice-bar v-if="item.status==1" :text="'审核失败：'+item.remark" mode="closable"
							:bgColor='"rgba(255,0,0,0.5)"' color='#fff'></u-notice-bar>
						<u-alert v-if="item.status==2" title="审核通过" type="success"></u-alert>
					</view>
					<view class="userBox">
						<u-avatar size='80rpx' :src='item.user.avatar' />
						<view class="userInfo">
							<view>
								{{item.user.nick_name}}
							</view>
							<view>
								{{item.created_at | changeTime}}
							</view>
						</view>
						<view class="activeProcess">
							{{item.process.title}}
						</view>
						<u-icon name="more-dot-fill" size="40rpx" @click='openSelect(item)'></u-icon>
					</view>
					<view style="margin: 10rpx 0;">
						<u-parse :content="item.title"></u-parse>
					</view>
					<view>
						<album :ref='`album${index}`' :imageList='item.images'
							:video='item.videos.map(imageItem=>imageItem.url)' :index='index' :playIndex='playIndex' />
					</view>
				</view>
				<view v-if="!active.length">
					<empty />
				</view>
			</template>
			<template>
				<activeVerify @reload='reload' :show='verifyId' @close='verifyId=0'></activeVerify>
			</template>
		</view>
		<root-portal>
			<u-picker keyName="title" :show="show" :columns="processesList" @confirm='confirm'
				@cancel='show=false'></u-picker>
			<u-action-sheet :actions="columns" :show="selectShow" @close='selectShow=false' @select="actionSelect"
				closeOnClickOverlay></u-action-sheet>
			<u-modal :show="delShow" content='是否确认删除？' showCancelButton @confirm='del'
				@cancel='delShow=false'></u-modal>
		</root-portal>
	</view>
</template>

<script>
	import album from '@/components/album.vue';
	import activeVerify from '@/components_company/activeVerify.vue';
	export default {
		components: {
			album,
			activeVerify
		},
		props: ['loading', 'prorcessesId', 'activities', 'playIndex', 'processes'],
		computed: {
			active() {
				return this.activities
			},
			processesList() {
				return [this.processes]
			},
			processesTitle() {
				if (this.prorcessesId) {
					return this.processes.filter(item => item.id == this.prorcessesId)[0].title
				}

				return '阶段筛选'
			}
		},
		data() {
			return {
				verifyId: 0,
				delShow: false,
				show: false,
				selectShow: false,
				selectItem: null,
				columns: [{
						name: '编辑'
					},
					{
						name: '删除'
					},
					{
						name: '审核'
					}
				],
			}
		},
		mounted() {

		},
		methods: {
			reload() {
				this.$emit('reload')
				this.$emit('refresher_enabled_change', true)
			},
			Verify() {
				this.verifyId = this.selectItem.id
				this.$emit('refresher_enabled_change', false)
				this.$emit('loadingChange')
			},
			del() {
				this.delShow = false
				this.$emit('loadingChange')
				this.$api_company.Active.Del(this.selectItem.id).then(res => {
					this.$emit('reload')
				}).catch(err => {
					this.$emit('loadingChange')
				})
			},
			upDate() {
				this.$utils.navigateTo({
					url: "/active/upDate?id=" + this.selectItem.id
				})
			},
			actionSelect(e) {
				this.selectShow = false
				this.$emit('refresher_enabled_change', true)
				if (e.name == '编辑') {
					if (this.selectItem.status == 2) {
						uni.$u.toast('审核已通过，不能编辑')
						return
					}
					this.upDate()
				} else if (e.name == '删除') {
					this.delShow = true
				} else if (e.name == '审核') {
					if (this.selectItem.status == 2) {
						uni.$u.toast('审核已通过，无需在审核')
						return
					}
					this.Verify()
				}
			},
			openSelect(item) {
				this.selectShow = true
				this.selectItem = item
				this.$emit('refresher_enabled_change', false)
			},
			confirm(e) {
				this.$emit('prorcessesChange', e.value[0].id)
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.infoBox {
		border-radius: 8rpx;
		background-color: #fff;
		box-shadow: 0 0 10rpx #eee;
		width: 680rpx;
		margin: 20rpx auto 0;

		.infoTitle {
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #ddd;
			padding: 20rpx 40rpx;
			justify-content: space-between;

			.title {
				flex: 1;
				font-size: 28rpx;
				margin-left: 20rpx;
			}
		}

		.infoContent {
			padding: 20rpx 40rpx;
		}
	}

	.userBox {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;

		>view:nth-child(2) {
			flex: 1;
			margin: 0 20rpx;
			height: 80rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
		}

		.activeProcess {
			color: #fff;
			background-color: green;
			border-radius: 4rpx;
			padding: 4rpx 10rpx;
			margin-right: 10rpx;
		}
	}

	.mb20 {
		padding: 0 0 20rpx;
		border-bottom: 1rpx solid #ddd;
		margin-bottom: 20rpx;
	}
</style>